/*
 * A Gneral purpose java based Genome Library created by Susanta Tewari.
 * Copyright is protected. Contact Susanta Tewari at <statsusant@yahoo.com>
 */

package genomemap.barratt;

import org.stat.model.data.Data;
import org.stat.model.data.DataAttribute;
import org.stat.model.data.ModelData;
import org.stat.model.data.NumericData;
import org.stat.model.data.Record;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Susanta Tewari <stewari@yahoo.com>
 */
public class BarrattModelData extends ModelData {

    /**
     * recombination distance
     */
    private static final String Y = "y";

    /**
     * physical distance
     */
    public static final String X = "x";

    /** Field description */
    private final List<Record> records = new ArrayList<>();

    /** Field description */
    private final Record recordProtoType;

    /**
     * Constructs ...
     */
    public BarrattModelData() {

        this.requestDataLabel  = "Recombination Distance";
        this.responseDataLabel = "Physical Distance";

        DataAttribute physicalDistDataAtt = new DataAttribute(X, DataAttribute.DataType.NUMBER);
        DataAttribute recomDistDataAtt    = new DataAttribute(Y, DataAttribute.DataType.NUMBER);

        this.dataAttributes  = new DataAttribute[] { physicalDistDataAtt, recomDistDataAtt };
        this.recordProtoType = new Record(new Data[] { new NumericData(), new NumericData() },
                                          this);
        this.requestIndices  = new boolean[] { true, false };    // sets the request data
        this.responseIndices = new boolean[] { false, true };    // must be response data.
    }

    public void addData(String physicalDist, String recomDist) {

        Record record = recordProtoType.cloneDefaultInstance();

        record.setValue(Y, recomDist);
        record.setValue(X, physicalDist);
        records.add(record);
    }

    @Override
    public Record[] getRecords() {
        return this.records.toArray(new Record[0]);
    }
}
